<template>
	<view class="uni_box home">
		<navbar title='投诉反馈'>
			<view class="hright" slot="right" @click="gettousu">
				<text>反馈记录</text>
			</view>
		</navbar>
		<view class="content">
			<view class="shenview">
				<view class="shenone">
					<text class="cname">问题反馈</text>
				</view>
				<view class="suview">
					<u-input v-model="content" :type="type" :border="border" :height="height" :auto-height="autoHeight" />
				</view>
				<view class="tuview">
					<view class="tuitem" v-if="images.length<3" @click="upload">
						<image class="addtu" src="/static/img/btn_tupian.png"></image>
					</view>
					<view class="tuitem" v-for="(item,index) in images" :key="index">
						<view class="cha" @click="previewImage(item)">
							<text>查看示例图</text>
						</view>
						<image class="addtu" :src="item"></image>
					</view>
				</view>
			</view>
			<view class="fabu" @click="gettou">提交</view>
		</view>
	</view>
</template>

<script>
import {
		baseUrl
	} from '@/utils/config.js';
	export default {
		data() {
			return {
				value: '',
				type: 'textarea',
				border: false,
				height: 100,
				autoHeight: true,
				images:[],
				content:'',
				headimg:''
			}
		},
		onLoad() {
			
		},
		onShow() {
		},
		methods: {
			gettousu(){
				// this.navrouter("/pages_subject/twoPage/TouSuRecord");
				this.navrouter("/pages_subject/twoPage/TouSuList");
			},
			async gettou(){
				if(!this.content){
					this.$u.toast("请输入内容");
					return false;
				}
				let res = await this.$u.api.addFankui({
					content:this.content,
					images:this.images.toString()
				});
				this.$u.toast("提交成功");
				this.content =''
				this.images = []
			},
			upload(e) {
				// this.updatetype = e
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						this.headimg = tempFilePaths[0];
						// this.isClick = true;
						this.unloadtou()
						// this.getavatar();//修改信息
					}
				});
			},
			unloadtou(){
				// console.log(this.head_portrait)
				let that = this
				uni.uploadFile({
					// url: baseUrl + '/api/uploadImage', //仅为示例，非真实的接口地址
					url: baseUrl + '/common/upload', //仅为示例，非真实的接口地址
					filePath: this.headimg,
					name: 'file',
					header: {
						// 'content-type': 'application/json;charset=UTF-8',
						'token':uni.getStorageSync('token'),
					},
					formData: {
						'token':uni.getStorageSync('token'),
					},
					success: (uploadFileRes) => {
						console.log( JSON.parse(uploadFileRes.data).data);
						let tu = JSON.parse(uploadFileRes.data).data.fullurl
						let images =  that.images
						images.push(tu)
						that.images = images
						// that.getavatar();//修改信息
						// that.getinfo()
					}
				});
			},
			chaitem(item){

			},
			previewImage(item){
				// console.log('index', index)
				let a= []
				// let list = this.list
				// for(let i in list){
				a.push(item)
				// }
				uni.previewImage({
					current: item, //预览图片的下标
					urls: a//预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.content{
		min-height: 100vh;
		background-color: #f5f5f5;
		padding: 30rpx;
		.shenview{
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 10rpx 20rpx 40rpx;
			.shenone{
				border-bottom: 1rpx solid #eee;
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: 20rpx 0;
				margin-bottom: 30rpx;
				.cname{
					font-family: PingFang SC;
					font-weight: bold;
					font-size: 32rpx;
					color: #111111;
				}
			}
			.smiao{
				display: block;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #999999;
				margin-top: 30rpx;
			}
			.suview{
				padding:20rpx 30rpx;
				background: #F5F5F5;
				border-radius: 20rpx;

			}
		}

		.tuview{
			display: flex;
			flex-direction: row;
			flex-wrap: wrap;
			margin-top: 30rpx;
			.tuitem{
				width: 180rpx;
				height: 180rpx;
				position: relative;
				border-radius: 10rpx;
				margin: 0 20rpx 20rpx 0;
				.addtu{
					position: absolute;
					width: 100%;
					height: 100%;
					border-radius: 10rpx;
				}
				.cha{
					background-color: rgba(0, 0, 0, 0.4);
					position: absolute;
					width: 100%;
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
					border-radius: 10rpx;
					z-index: 10;
					text{
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 24rpx;
						color: #FFFFFF;
					}
				}
			}
		}
	}
	.fabu{
		margin: 30rpx;
		height: 88rpx;
			background: linear-gradient(90deg, #0DBFFB, #198EFF);
		border-radius: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 36rpx;
		color: #FFFFFF;
	}
	
</style>
